from typing import Optional
from pydantic import BaseModel, Field,field_validator
from urllib.parse import urlparse

class ConvertRequest(BaseModel):
    """Request model for WebP to PNG conversion."""
    
    image_url: str = Field(
        description="URL of the WebP image to convert"
    )

    @field_validator("image_url")
    def validate_image_url(cls, v):
        """Validate that image_url is a valid URL."""
        if not v:
            raise ValueError("image_url must be provided")
        parsed = urlparse(v)
        if not parsed.scheme or not parsed.netloc:
            raise ValueError("Invalid URL format")
        return v


class ConvertResponse(BaseModel):
    success: bool = Field(description="Whether the conversion was successful")
    convert_image_url: str = Field(
        default=None,
        description="PNG image url"
    )